
//
// 版权所有 (c) 2021-2023 JR
//
// 特此免费授予获得本软件的任何人以处理本软件的权利，但须遵守以下条件：在所有副本或重要部分的软件中必须包括上述版权声明和本许可声明。
//
// 软件按“原样”提供，不提供任何形式的明示或暗示的保证，包括但不限于对适销性、适用性和非侵权的保证。
// 在任何情况下，作者或版权持有人均不对任何索赔、损害或其他责任负责，无论是因合同、侵权或其他方式引起的，与软件或其使用或其他交易有关。

namespace EMC.VISITOR.Core;

/// <summary>
/// 框架实体基类Id
/// </summary>
public abstract class EntityBaseId
{
    /// <summary>
    /// 雪花Id
    /// </summary>
    [SugarColumn(ColumnDescription = "Id", IsPrimaryKey = true, IsIdentity = false)]
    ////给序列赋值 现在我们就可以实现自增列  Oracle12C以下不支持自增列,所以我们需要使用序列来实现自增列 
    //[SqlSugar.SugarColumn(IsPrimaryKey = true, OracleSequenceName = "SEQ_ID")]
    public virtual long Id { get; set; }

    [SugarColumn(IsIgnore = true)]
    [JsonProperty("$cellEdit")]
    public virtual bool? cellEdit { get; set; } = true;
}



/// <summary>
/// 框架实体基类
/// </summary>
public abstract class EntityBase : EntityBaseId, IDeletedFilter
{
    /// <summary>
    /// 创建时间
    /// </summary>
    [SugarColumn(ColumnDescription = "创建时间", IsNullable = true, IsOnlyIgnoreUpdate = true)]
    public virtual DateTime? CreateTime { get; set; }


    /// <summary>
    /// 更新时间
    /// </summary>
    [SugarColumn(ColumnDescription = "更新时间",IsNullable =true, IsOnlyIgnoreInsert = true)]
    public virtual DateTime? UpdateTime { get; set; }

    /// <summary>
    /// 创建者Id
    /// </summary>
    [SugarColumn(ColumnDescription = "创建人", IsNullable = true, IsOnlyIgnoreUpdate = true)]
    public virtual long? CreateUserId { get; set; } = 0;

    /// <summary>
    /// 修改者Id
    /// </summary>
    [SugarColumn(ColumnDescription = "修改人",IsNullable =true, IsOnlyIgnoreInsert = true)]
    public virtual long? UpdateUserId { get; set; }

    /// <summary>
    /// 软删除
    /// </summary>
    [SugarColumn(ColumnDescription = "软删除")]
    public virtual bool IsDelete { get; set; } = false;

    ///// <summary>
    ///// 用于乐观锁解决并发问题
    ///  SqlServer中的时间戳类型的字段，会在这条记录变更后会自动更新，如果没这种机质的字段你也可以用触发器实现这种机质timestamp（默认自动更新）
    ///// </summary>
    //[SqlSugar.SugarColumn(
    //        IsEnableUpdateVersionValidation = true,//标识版本字段 
    //        IsOnlyIgnoreInsert = true,//禁止插入
    //        IsOnlyIgnoreUpdate = true,//禁止更新
    //        ColumnDataType = "timestamp" //时间戳类型，有些库需要配置或者有差异
    //         )]

    //// SqServer byte[] 其它数据库用 DateTime                        
    //public byte[] Timestamp { get; set; }

    public virtual async Task<Tuple<bool, string>> DoSomeThing(ISqlSugarClient _db = null)
    {
        return await Task.Run(() =>
        {
            return new Tuple<bool, string>(true, string.Empty);
        });
    }
    public virtual async Task<Tuple<bool, string>> SaveDoSomeThing(ISqlSugarClient _db = null)
    {
        return await DoSomeThing(_db);
    }

    public virtual async Task DoSomeThingSaveChildren(ISqlSugarClient _db = null)
    {
        await Task.CompletedTask;
    }
}

/// <summary>
/// 业务数据实体基类(数据权限)
/// </summary>
public abstract class EntityBaseData : EntityBase, IOrgIdFilter
{
    /// <summary>
    /// 创建者部门Id
    /// </summary>
    [SugarColumn(ColumnDescription = "创建者部门Id", IsNullable = true, IsOnlyIgnoreUpdate = true)]
    public virtual long? CreateOrgId { get; set; } = 0;
}
/// <summary>
/// 审核数据实体基类
/// </summary>
public abstract class EntityBaseDataAudit : EntityBaseData, IAuditFilter
{
    [SugarColumn(ColumnDescription = "审核编码", IsOnlyIgnoreUpdate = true)]
    public virtual string AuditCode { get; set; }
}
/// <summary>
/// 租户基类实体
/// </summary>
public abstract class EntityTenant : EntityBase, ITenantIdFilter
{
    /// <summary>
    /// 租户Id
    /// </summary>
    [SugarColumn(ColumnDescription = "租户Id", IsNullable = true, IsOnlyIgnoreUpdate = true)]
    public virtual long? TenantId { get; set; }
}

/// <summary>
/// 租户基类实体Id
/// </summary>
public abstract class EntityTenantId : EntityBaseId, ITenantIdFilter
{
    /// <summary>
    /// 租户Id
    /// </summary>
    [SugarColumn(ColumnDescription = "租户Id", IsNullable = true, IsOnlyIgnoreUpdate = true)]
    public virtual long? TenantId { get; set; }
}